package test;

import java.io.File;

import jxl.Cell;
import jxl.CellType;
import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class CreateExcel {
    public static void main(String args[]) {
        try {
        	
        	int n = -1;
        	
        	Workbook book = Workbook.getWorkbook(new File("test.xls"));
    		WritableWorkbook book2 = Workbook.createWorkbook(new File("test1.xls"),book);
            WritableSheet sheet = book2.getSheet(0);
            
            int totalRows = sheet.getRows();
        	
        	for(int i = 1; i <= totalRows ; i++){
        		               
                Cell cell1 = sheet.getCell(0, i-1);                
                Cell cell2 = sheet.getCell(0, i);
                
                String content1 = cell1.getContents();
                String content2 = cell2.getContents();
                String result1 = content1.substring(13, 20);
                
                if(cell2.getType() != CellType.EMPTY){
                	                	                
                    String result2 = content2.substring(13, 20);
                                        
                    if(Integer.parseInt(result2) - Integer.parseInt(result1) == 1){
                    	if(n == -1){
                    		
                    		n = i-1;
                    		
                    	}
                    	else continue;
                    }
                    
                    else {
                    	
                    	if(n > -1){
                        
                    		FillCell fillCell = new FillCell();
                    		fillCell.fillWith_n(sheet, n, i, content1, result1);

                    		n = -1;

                        }
                    	else {
                    		
                    		FillCell fillCell = new FillCell();
                    		fillCell.fillWith_1(sheet, i);
                    		
                    	}                	
                    }                	
                }
                
                else {
                	
                	if(n > -1){
                    
                		FillCell fillCell = new FillCell();
                		fillCell.fillWith_n(sheet, n, i, content1, result1);

                		n = -1;

                    }
                	
                	else{
                		
                			String result = content1.substring(0, 1);
                			if(result.equals("1") == false){
                				
                				FillCell fillCell = new FillCell();
                        		fillCell.fillWith_1(sheet, i);
                				
                			}               			
                			else break;
                			
                	}                		                		                		
                }               	                	                	               	
        	}
        	        	
        	DeleteNoNumRow deleteNoNumRow = new DeleteNoNumRow();
        	deleteNoNumRow.delete(totalRows, sheet);
        	
        	book2.write();
        	book2.close();
        	book.close();
                       
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}